#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

//struct ListNode
//{
//    int val;
//    struct ListNode* next;
//};
//
//struct ListNode* removeElements(struct ListNode* head, int val)
//{
//    struct ListNode* cur = head;
//    struct ListNode* prev = NULL;
//
//    while (cur)
//    {
//        if (cur->val == val)
//        {
//            struct ListNode* next = cur->next;
//            free(cur);
//            cur = next;
//            if(prev != NULL)
//                prev->next = next;
//        }
//        else
//        {
//            prev = cur;
//            cur = cur->next;
//        }
//    }
//    return head;
//}

//void test1()
//{
//    //struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //struct ListNode* n2 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //struct ListNode* n3 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //struct ListNode* n4 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //struct ListNode* n5 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //struct ListNode* n6 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //struct ListNode* n7 = (struct ListNode*)malloc(sizeof(struct ListNode));
//
//    //n1->val = 1;
//    //n2->val = 2;
//    //n3->val = 6;
//    //n4->val = 3;
//    //n5->val = 4;
//    //n6->val = 5;
//    //n7->val = 6;
//
//    //n1->next = n2;
//    //n2->next = n3;
//    //n3->next = n4;
//    //n4->next = n5;
//    //n5->next = n6;
//    //n6->next = n7;
//    //n7->next = NULL;
//
//    //struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    //n1->val = 1;
//    //n1->next = NULL;
//
//    struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
//    n1->val = 7;
//    n1->next = NULL;
//
//
//    struct ListNode* head = removeElements(n1, 7);
//}

struct ListNode 
{
    int val;
    struct ListNode* next;
};

struct ListNode* middleNode(struct ListNode* head)
{
    if (head == NULL)
        return NULL;
    struct ListNode* slow = head;
    struct ListNode* fast = head;
    while (fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
        if (fast->next == NULL)
            return slow;
        if (fast->next->next == NULL)
            return slow->next;
    }
}

void test2()
{
    struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* n2 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* n3 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* n4 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* n5 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* n6 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* n7 = (struct ListNode*)malloc(sizeof(struct ListNode));

    n1->val = 1;
    n2->val = 2;
    n3->val = 3;
    n4->val = 4;
    n5->val = 5;
    n6->val = 6;
    n7->val = 7;

    n1->next = n2;
    n2->next = n3;
    n3->next = n4;
    n4->next = n5;
    n5->next = n6;
    n6->next = n7;
    n7->next = NULL;

    struct ListNode* head = middleNode(n1);

}

int main()
{
    test2();

    return 0;
}

